import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';
import 'package:speed_random/app_styles.dart';
import 'package:speed_random/common/common_fuc.dart';
import 'package:speed_random/global_data.dart';
import 'package:speed_random/pages/home/rand_com/com_results/logic.dart';
import 'package:speed_random/pages/home/rand_com/com_results/state.dart';
import 'package:share_plus/share_plus.dart';

class ItemResultsRoller extends StatelessWidget {
  final ComResultsLogic logic;
  final ComResultsState state;
  final Map<String, dynamic> numbers;
  final Color textColor;
  final Color bgColor;
  final Function({String newShareText,String newcopyText}) onShareTextChanged; // 添加回调函数

  const ItemResultsRoller({
    Key? key,
    required this.logic,
    required this.state,
    required this.numbers,
    this.textColor = AppStyles.colorPageText,
    this.bgColor = AppStyles.colorPagebg,
    required this.onShareTextChanged, // 必须传入回调函数
  }) : super(key: key);





  @override
  Widget build(BuildContext context) {
    final diceNums = {
      '⚀': 1,
      '⚁': 2,
      '⚂': 3,
      '⚃': 4,
      '⚄': 5,
      '⚅': 6,
    };
    var numbersList=numbers["list"].split(",");

    var zonx = "总项".tr+"：${numbersList.length}";
    var Rolls = "Rolls".tr+"："+numbersList.map((num) => diceNums[num]).toString();
    var sumx = "总和".tr+"："+numbersList.map((num) => diceNums[num]??0).reduce((a, b) => a + b).toString();

   var newShareText=numbers["list"]+"\n"+Rolls+"\n"+zonx+"    "+sumx;
    onShareTextChanged(newShareText: newShareText,newcopyText: newShareText);
    return Column(
      mainAxisAlignment: MainAxisAlignment.center,
      crossAxisAlignment: CrossAxisAlignment.center,
      children: [
        // ... 已有代码 ...
        Wrap(
          alignment: WrapAlignment.center, // 确保Wrap内容居中
          spacing: 5.0,
          runSpacing: 5.0,
          children: numbersList.map<Widget>((number) {
            // 定义骰子面对应的颜色
            final diceColors = {
              '⚀': Colors.red,
              '⚁': Color(0xFF062DBA),
              '⚂': Color(0xFF062DBA),
              '⚃': Colors.red,
              '⚄': Color(0xFF062DBA),
              '⚅': Color(0xFF062DBA),
            };

            return Container(
             // padding: EdgeInsets.all(5),
              child: Text(
                "$number",
                style: TextStyle(
                  fontSize: 30,
                  fontWeight: FontWeight.bold,
                  color: diceColors[number] ?? state.randComArgs.value.colorPageText, // 使用骰子面颜色，如果没有匹配则使用默认颜色
                ),
              ),
            );
          }).toList(),
        ),
        Text(
          Rolls,
          style:  TextStyle(
            fontSize: 14,
            color: textColor,
          ),
        ),
        const SizedBox(height: 10),
          Row(
            mainAxisAlignment: MainAxisAlignment.center,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              Text(
                zonx,
                style:  TextStyle(
                  fontSize: 14,
                  color: textColor,
                ),
              ),
              SizedBox(width: 10),
              Text(
                sumx,
                style:  TextStyle(
                  fontSize: 14,
                  color: textColor,
                ),
              ),
            ],
          )
      ],
    );
  }
}
